﻿using System;
using System.Collections.Generic;

namespace PhotoGallery.Infrastructure.Roots.Configuration
{
    [System.Configuration.ConfigurationCollection(typeof(NamedConfigurationElementBase),
        CollectionType = System.Configuration.ConfigurationElementCollectionType.AddRemoveClearMap)]
    public abstract class NamedConfigurationElementCollectionBase<T> : System.Configuration.ConfigurationElementCollection
        where T : NamedConfigurationElementBase, new()
    {
        public T this[int index] { get { return (T)base.BaseGet(index); } }

        public new T this[string name] { get { return (T)base.BaseGet(name); } }

        protected override System.Configuration.ConfigurationElement CreateNewElement()
        {
            return new T();
        }

        protected override object GetElementKey(System.Configuration.ConfigurationElement element)
        {
            return (element as T).Name;
        }
    }

    public class RootElementCollection : NamedConfigurationElementCollectionBase<ModuleElement>
    {
    }
}
